package xan.tm.digital.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import xan.tm.digital.common.entity.BaseResponse;
import xan.tm.digital.common.enums.ErrorCodeEnum;
import xan.tm.digital.common.utils.ResultUtil;


/**
 * 全局异常处理器 * @date 2023/06/22
 */
@RestControllerAdvice
@Slf4j
public class BusinessExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException e) {
        log.error("businessException: ", e);
        return ResultUtil.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler({MaxUploadSizeExceededException.class})
    public BaseResponse<?> handlerMaxUploadErrorException(Exception e) {
        log.error("文件上传大小超限", e);
        return ResultUtil.error(ErrorCodeEnum.FILE_SIZE_LIMIT_ERROR);
    }

}
